package com.wuliu.system.service.rabbitmq;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.constant.RabbitMQConstants;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.domain.SysSmsRecord;
import com.wuliu.system.mapper.SysSmsRecordMapper;
import com.wuliu.system.service.ISysSmsRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

/**
 * 消费者服务
 *
 * @author realue
 * @version 1.0
 * @date 2024-04-24 14:44
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ConsumerService {

    private final ISysSmsRecordService sysSmsRecordService;

    /**
     * 消费短信
     *
     * @param smsId 短信ID
     */
    @RabbitListener(queuesToDeclare = @Queue(value = RabbitMQConstants.SMS_QUEUE_NAME, durable = "true"))
    public void consumerSms(String smsId) {
        SysSmsRecord sysSmsRecord = sysSmsRecordService.getOne(new LambdaQueryWrapper<SysSmsRecord>()
                .eq(SysSmsRecord::getId, smsId)
                .eq(SysSmsRecord::getStatus, 0));
        if (null != sysSmsRecord) {
            sysSmsRecordService.sendSms(sysSmsRecord);
        }
    }

    /**
     * 消费订单延迟队列
     * @param orderId
     */
    @RabbitListener(queuesToDeclare = @Queue(value = RabbitMQConstants.ORDER_DELAY_QUEUE_NAME, durable = "true"))
    public void consumerOrderDelay(String orderId) {
        log.info("订单延迟队列消费者收到消息，订单号：{}", orderId);
        // TODO 订单延迟队列消费者逻辑
    }
}
